/** 
 * 自定义My页面的JS
 * */
 
 
 
 
 
//自动加载
mui.plusReady(function () {
	(function($, owner) {
		// 用户信息
		getUserInfo();
		// 统计
		getTotal();
		// setSign();
	}(mui, window.app = {}));
});
// 获取用户信息
function getUserInfo(){
	// 判断用户登陆
	var userInfo = cacheGet(userInfoKey);
	if (!userInfo) {
		mui.toast('没有登陆',{ 
			duration:'short', type:'div',
		});
		setTimeout(function(){
			jumpToMyLogin();
		}, 500);
		return 
	}
	// mui.alert('?'+userInfo.appHeadBg); return
	// 用户信息
	var uname = getStrLimitNum(userInfo.name, 10);
	var udetail = getStrLimitNum(userInfo.detail, 10);
	mui("#uname")[0].innerHTML = uname;
	mui("#udetail")[0].innerHTML = udetail;
	// 用户头像
	if (userInfo.appHead) {
		// document.getElementById('uHead').src = userInfo.appHead;
		mui("#uHead")[0].src = userInfo.appHead;
	} else if (userInfo.head) {
		// document.getElementById('uHead').src = userInfo.head;
		mui("#uHead")[0].src = userInfo.head;
	} else {
		// document.getElementById('uHead').src = '../imgs/tmp2.png';
		mui("#uHead")[0].src = '../imgs/tmp2.png';
	}
	// 用户头像背景
	if (userInfo.appHeadBg) {
		mui("#uHeadBg")[0].src = userInfo.appHeadBg;
	} else if (userInfo.head) {
		mui("#uHeadBg")[0].src = userInfo.appHeadBg;
	} else {
		mui("#uHeadBg")[0].src = '../imgs/tmp2.png';
	}
}
// 获取点赞/收藏统计
function getTotal(){
	// mui("#zanTotal")[0].innerHTML = cache.list.length;
	var indexList = getIndexCache();
	var marketList = getMarketCache();
	var resIndex = indexList.list;
	var resMarket = marketList.list;
	var zanTotal = 0;
	var collectTotal = 0;
	var plusTotal = 0;
	// mui.toast('??'+resIndex[0].zanTotal)
	if (resIndex.length > 0) {
		for (var i=0;i<resIndex.length;i++) {
			zanTotal = zanTotal * 1 + resIndex[i].zanTotal;
			collectTotal = collectTotal * 1 + resIndex[i].collectTotal;
		}
	}
	if (resMarket.length > 0) {
		for (var m=0;m<resMarket.length;m++) {
			zanTotal = zanTotal * 1 + resMarket[m].zanTotal;
			collectTotal = collectTotal * 1 + resMarket[m].collectTotal;
			plusTotal = plusTotal * 1 + resMarket[m].plusTotal;
		}
	}
	mui("#zanTotal")[0].innerHTML = zanTotal;
	mui("#collectTotal")[0].innerHTML = collectTotal;
	mui("#plusTotal")[0].innerHTML = plusTotal;
}
//获取首页数据缓存
function getIndexCache(){
	var resList = cacheGet(indexList);
	if (!resList) {
		var list = new Array(),  //数据数组
			idstring = ''; //ID字符串集合
		return {
			// 数据数组
			list: list,
			// 历史ID集合
			idstr: idstring
		};
	}
	return resList;
}
//获取库数据缓存
function getMarketCache(){
	var resList = cacheGet(marketList);
	if (!resList) {
		var list = new Array(),  //数据数组
			idstring = ''; //ID字符串集合
		return {
			// 数据数组
			list: list,
			// 历史ID集合
			idstr: idstring
		};
	}
	return resList;
}
////////////////图片处理////////////////
// 上传头像图片
function setHeadUpload(){
	// 系统参数
	var sys = getSys();
	var uploadDomain = sys.domain + '/app/user/head/tmp';
	var modifyDomain = sys.domain + '/app/user/head/modify';
	// 上传参数
	var configs = {
		selector:'uHead',
		cacheKey:'userInfo', //用户信息
		cacheField:'appHead', //字段信息
		uploadUrl:uploadDomain,
		modifyUrl:modifyDomain
	};
	choosePhoto(configs);
}
// 上传头像背景图片
function setHeadBgUpload(){ 
	// mui.toast('44'); return
	// 系统参数
	var sys = getSys();
	var uploadDomain = sys.domain + '/app/user/headbg/tmp';
	var modifyDomain = sys.domain + '/app/user/headbg/modify';
	// 上传参数
	var configs = {
		selector:'uHeadBg',
		cacheKey:'userInfo', //用户信息
		cacheField:'appHeadBg', //字段信息
		uploadUrl:uploadDomain,
		modifyUrl:modifyDomain
	};
	choosePhoto(configs);
}
////////////////图片处理////////////////